package mylab.base.foundation.template.pojo;

import com.google.common.base.MoreObjects;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import lombok.Getter;
import mylab.base.foundation.lang.TreeNode;

@Getter
public class Tree<T extends TreeNode<T>> extends Pojo implements TreeNode<T> {

    T parent;
    final T node;
    final List<T> children = new CopyOnWriteArrayList<>();


    public Tree(T node) {
        this(null, node);
    }

    public Tree(T parent, T node) {
        this.parent = parent;
        this.node = node;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("node", node)
                .add("children", children)
                .toString();
    }
}
